{% extends 'layout.html' %}
{% load deploy %}

{% block content %}
    <div class="container">
        <div style="margin: 5px 0;">
            <a href="{% url 'project_env_add' %}" class="btn btn-primary">添加</a>
        </div>
        <div>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>项目</th>
                    <th>环境</th>
                    <th>线上路径</th>
                    <th>服务器列表</th>
                    <th>发布任务</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                {% for item in queryset %}
                    <tr>
                        <td>{{ item.id }}</td>
                        <td>{{ item.project }}</td>
                        <td>{{ item.get_env_display }}</td>
                        <td>{{ item.path }}</td>
                        <td>
                            {% for server in item.servers.all %}
                                <span style="border: 1px solid #dddddd; padding: 5px;">{{ server.hostname }}</span>
                            {% endfor %}
                        </td>
                        <td>
                            <a href="{% url 'deploy_task_list' env_id=item.id %}">发布任务（{% un_deploy_num item %}）</a>
                        </td>
                        <td>
                            <a href="{% url 'project_env_edit' pk=item.pk %}">编辑</a>
                            <a href="javascript:void(0);"
                               onclick="removeRow(this,'{% url 'project_env_del' pk=item.id %}');">删除</a>
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    </div>

{% endblock %}

{% block js %}
    <script type="text/javascript">
        function removeRow(ths, url) {
            var result = confirm('是否确定要删除？');
            if (result) {
                $.ajax({
                    url: url,
                    type: 'GET',
                    dataType: "JSON",
                    success: function (arg) {
                        if (arg.status) {
                            $(ths).parent().parent().remove();
                        }
                    }
                })
            }
        }
    </script>
{% endblock %}
